package api

import (
	"net/http"
	"gitee.com/DengAnbang/Computation/src/dbops"
	"gitee.com/DengAnbang/Computation/src/bean"
	"gitee.com/DengAnbang/Computation/src/util"
)

func UserRegisterHttp(_ http.ResponseWriter, r *http.Request) error {
	loginName := util.GetValueFormRequest(r, "login_name")
	pwd := util.GetValueFormRequest(r, "pwd")
	name := util.GetValueFormRequest(r, "name")
	user, err := dbops.UserRegister(loginName, pwd, name)
	if err != nil {
		return err
	}

	return bean.NewSucceedMessage(user)
}

func UserLoginHttp(_ http.ResponseWriter, r *http.Request) error {
	loginName := util.GetValueFormRequest(r, "login_name")
	pwd := util.GetValueFormRequest(r, "pwd")
	user, err := dbops.UserLogin(loginName, pwd)
	if err != nil {
		return err
	}
	//newSession, err := session.CreateNewSession(user.UserId)
	//if err != nil {
	//	return err
	//}
	//user.SessionId = newSession.SessionID
	return bean.NewSucceedMessage(user)

}
